﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Management;

namespace MYTech.Net
{
    public class NetHelper
    {
        public static string GetLocalIP()
        {
            string strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            return ipEntry.AddressList[0].ToString();
        }

        public static string GetLocalMac()
        {
            ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection queryCollection = query.Get();
            foreach (ManagementObject mo in queryCollection)
            {
                if (mo["IPEnabled"].ToString() == "True")
                    return mo["MacAddress"].ToString();
            }
            return null;
        }
    }
}
